package com.jk.controller;

import com.alibaba.fastjson.JSONObject;
import com.jk.bean.Reset;
import com.jk.utils.HttpClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("http")
public class HttpController {
	
	@ResponseBody
	@RequestMapping(value="journalism",produces = "application/json; charset=utf-8")
	public Reset journalism(String type){
		//使用httpclient 调用第三方接口
		Map<String, Object> params = new HashMap();

		params.put("key", "c04b9f2c495cce9c887f6620deedd913");
		params.put("type", type);
		String result = HttpClient.sendGet("http://v.juhe.cn/toutiao/index", params);
		//result是一个json字符串  
		//json字符串 --> 对象
		JSONObject parseObject = JSONObject.parseObject(result);
		JSONObject results = parseObject.getJSONObject("result");
		List<Object> jsonArray = null;
		try {
			jsonArray = results.getJSONArray("data");
		} catch (Exception e) {
			e.printStackTrace();
		}
		Reset reset = new Reset();
		reset.setJournalism(jsonArray);
		return reset;
	}
	/*//生成二维码
	@ResponseBody
	@RequestMapping(value="code",produces = "application/json; charset=utf-8")
	public String  getCode(String text){
		//使用httpclient 调用第三方接口
		Map<String, Object> params = new HashMap();
		params.put("key", "31ec03209c8bb30cbc665d7370f59b61");
		params.put("text", text);
		String result = HttpClient.sendGet("http://apis.juhe.cn/qrcode/api", params);
		//result是一个json字符串
		//json字符串 --> 对象
		JSONObject parseObject = JSONObject.parseObject(result);
		JSONObject results = parseObject.getJSONObject("result");
		String  code= results.getString("base64_image");
		return code;
	}*/
}
